package com.txc.pay.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.ibatis.type.BlobTypeHandler;

import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;

/**
 * <p>
 * 支付商户账号配置表
 * </p>
 *
 * @author TXC
 * @since 2023-12-27
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("p_sys_account")
public class AccountEntity extends Model<AccountEntity> {

    private static final long serialVersionUID=1L;

    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.ASSIGN_UUID)
    private String id;

    /**
     * 用户id
     */
    @TableField("user_id")
    private String userId;

    /**
     * 支付账号配置
     */
    @TableField("param")
    private String param;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
      @TableField(value = "update_time", fill = FieldFill.INSERT)
    private LocalDateTime updateTime;

    /**
     * 是否为默认支付账号
     */
    @TableField("is_default")
    private int isDefault;

    /**
     * 账号状态
     */
    @TableField("status")
    private int status;

    /**
     * 逻辑删除
     */
    @TableField("is_delete")
    private int isDelete;

    /**
     * 描述
     */
    @TableField("description")
    private String description;

    /**
     * 支付类型（如：微信/支付宝等）
     */
    @TableField("pay_type")
    private String payType;

    /**
     * 私钥
     */
    @TableField(value = "private_key", typeHandler = BlobTypeHandler.class)
    private byte[] privateKey;

    public String formatPrivateKey() {
        return new String(privateKey, StandardCharsets.UTF_8).replaceAll("\r", "");
    }
    @Override
    public Serializable pkVal() {
        return this.id;
    }

}
